﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.email
{
    public partial class box_edit : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int boxId = (Request.QueryString["box_id"] != null) ? int.Parse(Request.QueryString["box_id"].ToString()) : 0;
                this.ViewState["BoxId"] = boxId;
                DataTable table = new EmailBoxDao().SelectByBoxId(base.Conn, boxId, base.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    this.txtBoxNo.Text = table.Rows[0]["BoxNo"].ToString();
                    this.txtBoxName.Text = table.Rows[0]["BoxName"].ToString();
                }
                else
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无记录", "box.aspx");
                }
            }
            if (this.Page.IsPostBack)
            {
                EmailBoxDao dao2 = new EmailBoxDao();
                EmailBoxData data = new EmailBoxData();
                data.BoxId = Convert.ToInt32(this.ViewState["BoxId"].ToString());
                data.UserId = base.User.Identity.Name;
                data.BoxNo = Convert.ToInt32(this.txtBoxNo.Text);
                data.BoxName = this.txtBoxName.Text;
                dao2.Update(base.Conn, data);
                base.CloseConn();
                Response.Redirect("box.aspx");
                if (!this.ClientScript.IsStartupScriptRegistered(this.GetType(), "refresh"))
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "refresh", " window.location='box.aspx';window.parent.mail_menu.location.reload();", true);
                }
            }
        } 

    }
}
